package dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class ConnectionFactory {

	private Connection cnx;

	public ConnectionFactory()	{
		setCnx(cnx);
	}

	
	public Connection getCnx() {
		return cnx;
	}

	public void setCnx(Connection cnx) {
		this.cnx = cnx;
	}


	
	public Connection getConnection(String nomPilote, String URLBD,
			String autorisationID, String password) throws SQLException,
			ClassNotFoundException {

		Class.forName(nomPilote);

		cnx = DriverManager.getConnection(URLBD, autorisationID, password);

		cnx.setAutoCommit(true);

		return cnx;

	}

	public Connection getConnectionSansAutoCommit(String nomPilote,
			String URLBD, String autorisationID, String password)
			throws SQLException, ClassNotFoundException {

		Class.forName(nomPilote);

		cnx = DriverManager.getConnection(URLBD, autorisationID, password);

		cnx.setAutoCommit(false);

		return cnx;
	}

}
